home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / sipp / srgp / src / srgp_sta.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-01  |  5.3 KB  |  262 lines

  1. #include "HEADERS.h"
  2. #define SRGP_BOSS
  3. #include "srgplocal.h"
  4.  
  5. static char message[] =  "Unable to open the SRGP logfile!";
  6.  
  7. int SRGP_errorOccurred = 0;
  8.  
  9. errorHandlingMode srgp__curErrHndlMode = FATAL_ERRORS;
  10.  
  11.  
  12.  
  13. /** SRGP_tracing
  14. **/
  15. void
  16. SRGP_tracing (boolean please_trace)
  17. {
  18.  
  19.    if ( ! SRGP_logStream) {
  20.       /* LOGGING FILE IN LINE-BUFFERED MODE. */
  21.       if (SRGP_logStream = fopen ("SRGPlogfile", "w"))
  22. #ifdef sun
  23.      setvbuf (SRGP_logStream, NULL, _IOLBF, 512);
  24. #else
  25.       {}
  26. #endif
  27.       else {
  28. #ifdef THINK_C
  29.      ReportSpecialError (message, NON_FATAL);
  30.      return;  /* we can't enable it, but we can continue! */
  31. #else
  32.      fprintf (stderr, "%s\n", message);
  33.      exit (1);
  34. #endif
  35.       }
  36.    }
  37.  
  38.    SRGP_trace (SRGP_logStream, "---- TRACE DISABLED\n");
  39.    srgp__traceDisabled = ! please_trace;
  40.    SRGP_trace (SRGP_logStream, "++++ TRACE ENABLED\n");
  41. }
  42.  
  43.  
  44. void
  45. SRGP_disableDebugAids ()
  46. {
  47.    srgp__userDebugAidsDisabled = TRUE;
  48. }
  49.  
  50.  
  51. void
  52. SRGP_enableBlockedWait ()
  53. {
  54.    srgp__blockedWaitEnabled = TRUE;
  55. }
  56.  
  57.  
  58.  
  59. static void
  60. InitSRGP (char *name, int width, int height, int requested_planes, boolean debugasap)
  61. {
  62.    register cnt;
  63.  
  64.  
  65.    unlink ("./SRGPlogfile");
  66.  
  67.    ALLOC_RECORDS (srgp__bitmapPatternTable, pattern_table_entry, MAX_PATTERN_INDEX+1);
  68.    ALLOC_RECORDS (srgp__pixmapPatternTable, pixpat_table_entry, MAX_PATTERN_INDEX+1);
  69.    ALLOC_RECORDS (srgp__fontTable, fontInfo, MAX_FONT_INDEX+1);
  70.    ALLOC_RECORDS (srgp__cursorTable, cursorInfo, MAX_CURSOR_INDEX+1);
  71.    ALLOC_RECORDS (srgp__canvasTable, canvas_spec, MAX_CANVAS_INDEX+1);
  72. #ifdef X11
  73.    ALLOC_RECORDS (Xformat_vertices, XPoint, MAX_POINTLIST_SIZE);
  74. #endif
  75.  
  76.  
  77.    srgp__curActiveCanvasId = 0;
  78.    srgp__curActiveCanvasSpec.max_xcoord = (width-1);
  79.    srgp__curActiveCanvasSpec.max_ycoord = (height-1);
  80.  
  81.    SRGP__initGraphicsDevice (name, requested_planes, debugasap);
  82.  
  83.  
  84.    /*************** INIT. CANVAS TABLE TO SHOW THAT ONLY CANVAS 0 IS ALIVE */
  85.    srgp__canvasTable[0].drawable = srgp__curActiveCanvasSpec.drawable;
  86.    for (cnt=1; cnt <= MAX_CANVAS_INDEX; cnt++)
  87.       srgp__canvasTable[cnt].drawable.win = 0;
  88.  
  89.  
  90.    SRGP__initCursorTable();
  91.  
  92.    SRGP__initDefaultPatterns();
  93.  
  94.    SRGP__initFont();
  95.  
  96.    SRGP__setCanvasDefaults();
  97.  
  98.    srgp__resizeCallback = NULL;
  99.  
  100.    /* INIT TRACING ET.AL. */
  101.    srgp__traceDisabled = TRUE;
  102.    SRGP_logStream = NULL;
  103.  
  104.    SRGP__initInputModule();
  105. }
  106.  
  107.  
  108.  
  109.  
  110. /*!*/
  111. void SRGP_beginWithDebug
  112.    (char *name, int width, int height, int planes, boolean enable_trace)
  113. /* FOR USE BY SYSTEM ADMINS ONLY */
  114. {
  115.    if (srgp__enabled)
  116.       SRGP__error (ERR_ALREADY_ENABLED);
  117.    else {
  118.       srgp__enabled = TRUE;
  119.       InitSRGP (name, width, height, planes, TRUE);
  120.    }
  121.  
  122.    if (enable_trace)
  123.       SRGP_tracing (TRUE);
  124. }
  125.  
  126.  
  127. /*!*/
  128. void SRGP_begin
  129.    (char *name, int width, int height, int planes, boolean enable_trace)
  130. {
  131.    if (srgp__enabled)
  132.       SRGP__error (ERR_ALREADY_ENABLED);
  133.    else {
  134.       srgp__enabled = TRUE;
  135.       InitSRGP (name, width, height, planes, FALSE);
  136.    }
  137.  
  138.    if (enable_trace)
  139.       SRGP_tracing (TRUE);
  140. }
  141.  
  142.  
  143. /*!*/
  144. void SRGP_registerResizeCallback (funcptr resizeCall)
  145. {
  146.    srgp__resizeCallback = resizeCall;
  147. }
  148.  
  149.  
  150.  
  151. /*!*/
  152. void SRGP_end ()
  153. {
  154.    SRGP_trace (SRGP_logStream, "SRGP_end\n");
  155.  
  156. #  ifdef THINK_C
  157.    SRGP__cleanupMacMemory();
  158.    DisposeWindow (srgpmac__cwindow);
  159. #  endif
  160.  
  161. #ifdef GRX
  162.    SRGP__closeGraphicsDevice();
  163. #endif
  164.  
  165.    srgp__enabled = FALSE;
  166.    if (SRGP_logStream)
  167.       fclose (SRGP_logStream);
  168. }
  169.  
  170.  
  171.  
  172. void SRGP_setErrorHandlingMode (errorHandlingMode newmode)
  173. {
  174.    srgp__curErrHndlMode = newmode;
  175. }
  176.  
  177.  
  178. /** ROUTINES ALLOWING APPLICATION TO CHANGE SIZES OF TABLES
  179. These may only be called *before* SRGP is enabled.
  180. **/
  181.  
  182. static boolean CheckNotEnabledYet (void)
  183. {
  184.    if (srgp__enabled) {
  185.       SRGP__error (ERR_ALREADY_ENABLED);
  186.       return FALSE;
  187.    }
  188.    else
  189.       return TRUE;
  190. }
  191.  
  192.  
  193. void SRGP_setMaxCanvasIndex (int i)
  194. {
  195. if (CheckNotEnabledYet())
  196.    MAX_CANVAS_INDEX = i;
  197. }
  198.  
  199. void SRGP_setMaxPatternIndex (int i)
  200. {
  201. if (CheckNotEnabledYet())
  202.    MAX_PATTERN_INDEX = i;
  203. }
  204.  
  205. void SRGP_setMaxCursorIndex (int i)
  206. {
  207. if (CheckNotEnabledYet())
  208.    MAX_CURSOR_INDEX = i;
  209. }
  210.  
  211. void SRGP_setMaxFontIndex (int i)
  212. {
  213. if (CheckNotEnabledYet())
  214.    MAX_FONT_INDEX = i;
  215. }
  216.  
  217. void SRGP_setMaxPointlistSize (int i)
  218. {
  219. if (CheckNotEnabledYet())
  220.    MAX_POINTLIST_SIZE = i;
  221. }
  222.  
  223. void SRGP_setMaxStringSize (int i)
  224. {
  225. if (CheckNotEnabledYet())
  226.    MAX_STRING_SIZE = i;
  227. }
  228.  
  229.  
  230. #ifndef GRX
  231. void
  232. SRGP__reactToScreenResize (int www, int hhh)
  233. {
  234.    if (srgp__curActiveCanvasId == 0)
  235.       srgp__canvasTable[0] = srgp__curActiveCanvasSpec;
  236.  
  237.    srgp__canvasTable[0].max_xcoord = www - 1;
  238.    srgp__canvasTable[0].max_ycoord = hhh - 1;
  239.  
  240.    if (srgp__curActiveCanvasId == 0)
  241.       srgp__curActiveCanvasSpec = srgp__canvasTable[0];
  242.  
  243.    /* The locator measure needs to be updated, since its y coord is a
  244.       function of the max_ycoord of the screen canvas. */
  245.    srgp__cur_locator_measure.position.y =
  246.       srgp__canvasTable[0].max_ycoord - srgp__cur_Xcursor_y;
  247.  
  248.    if (srgp__resizeCallback)
  249.       (*srgp__resizeCallback) (www, hhh);
  250.  
  251. }
  252. #endif
  253.  
  254. void
  255. SRGP_changeScreenCanvasSize (int newwidth, int newheight)
  256. {
  257. #ifndef GRX
  258.    SRGP__forceScreenResize (newwidth, newheight);
  259.    SRGP__reactToScreenResize (newwidth, newheight);
  260. #endif
  261. }
  262.